﻿using System;
using ExFlash.Records;

namespace ExFlash.Filters
{
    public abstract class GradientFilter : ISwfSerializable
    {
        public Byte NumColors
        {
            get;
            protected set;
        }

        public RGBARecord[] GradientColors
        {
            get;
            protected set;
        }

        public Byte[] GradientRatio
        {
            get;
            protected set;
        }

        public FixedFloatRecord BlurX
        {
            get;
            protected set;
        }

        public FixedFloatRecord BlurY
        {
            get;
            protected set;
        }

        public FixedFloatRecord Angle
        {
            get;
            protected set;
        }

        public FixedFloatRecord Distance
        {
            get;
            protected set;
        }

        public FixedFloat8Record Strength
        {
            get;
            protected set;
        }

        public Boolean InnerShadow
        {
            get;
            protected set;
        }

        public Boolean Knockout
        {
            get;
            protected set;
        }

        public Boolean CompositeSource
        {
            get;
            protected set;
        }

        public Boolean OnTop
        {
            get;
            protected set;
        }

        public Byte Passes
        {
            get;
            protected set;
        }

        #region ISwfSerializable Members

        public void SwfDeserialize(BinaryBitReader reader)
        {
            NumColors = reader.ReadByte();

            GradientColors = new RGBARecord[NumColors];
            
            for (int i = 0; i < NumColors; i++)
            {
                GradientColors[i].SwfDeserialize(reader);
            }

            GradientRatio = new Byte[NumColors];

            for (int i = 0; i < NumColors; i++)
            {
                GradientRatio[i] = reader.ReadByte();
            }

            BlurX = new FixedFloatRecord();
            BlurX.SwfDeserialize(reader);

            BlurY = new FixedFloatRecord();
            BlurY.SwfDeserialize(reader);

            Angle = new FixedFloatRecord();
            Angle.SwfDeserialize(reader);

            Distance = new FixedFloatRecord();
            Distance.SwfDeserialize(reader);

            Strength = new FixedFloat8Record();
            Strength.SwfDeserialize(reader);

            InnerShadow = reader.ReadBoolean();
            Knockout = reader.ReadBoolean();
            CompositeSource = reader.ReadBoolean();
            OnTop = reader.ReadBoolean();
            Passes = (byte)reader.ReadInt32(4);
            reader.AlignBits();
        }

        public void SwfSerialize(byte[] arr, ref int offset)
        {
            throw new NotImplementedException();
        }

        #endregion
    }
}
